package com.evaluation_system.controller;

import com.evaluation_system.pojo.DTO.CheckerPageQueryDTO;
import com.evaluation_system.pojo.DTO.EvaluatorPageQueryDTO;
import com.evaluation_system.pojo.DTO.UploaderPageQueryDTO;
import com.evaluation_system.pojo.Result.PageResult;
import com.evaluation_system.pojo.Result.Result;
import com.evaluation_system.pojo.entity.Checker;
import com.evaluation_system.pojo.entity.Evaluator;
import com.evaluation_system.pojo.entity.Uploader;
import com.evaluation_system.service.CheckerService;
import com.evaluation_system.service.EvaluatorService;
import com.evaluation_system.service.UploadService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/admin/account")
@RequiredArgsConstructor
public class AdminController {

    private final UploadService uploaderService;
    private final CheckerService checkerService;
    private final EvaluatorService evaluatorService;

    // ========== Uploader ==========
    @GetMapping("/uploader/page")
    public Result<PageResult<Uploader>> getUploaderPage(UploaderPageQueryDTO uploaderPageQueryDTO) {
        log.info("分页查询:{}", uploaderPageQueryDTO);
        return Result.success(uploaderService.pageQuery(uploaderPageQueryDTO));
    }

    @PostMapping("/uploader")
    public Result<String> addUploader(@RequestBody Uploader uploader) {
        log.info("添加对象:{}", uploader);
        uploaderService.add(uploader);
        return Result.success("添加成功");
    }

    @PutMapping("/uploader")
    public Result<String> updateUploader(@RequestBody Uploader uploader) {
        log.info("修改对象:{}", uploader);
        uploaderService.update(uploader);
        return Result.success("更新成功");
    }

    @DeleteMapping("/uploader/{id}")
    public Result<String> deleteUploader(@PathVariable Integer id) {
        log.info("删除id为{}的数据", id);
        uploaderService.deleteById(id);
        return Result.success("删除成功");
    }

    // ========== Checker ==========
    @GetMapping("/checker/page")
    public Result<PageResult<Checker>> getCheckerPage(CheckerPageQueryDTO checkerPageQueryDTO) {
        return Result.success(checkerService.pageQuery(checkerPageQueryDTO));
    }

    @PostMapping("/checker")
    public Result<String> addChecker(@RequestBody Checker checker) {
        checkerService.add(checker);
        return Result.success("添加成功");
    }

    @PutMapping("/checker")
    public Result<String> updateChecker(@RequestBody Checker checker) {
        checkerService.update(checker);
        return Result.success("更新成功");
    }

    @DeleteMapping("/checker/{id}")
    public Result<String> deleteChecker(@PathVariable Integer id) {
        checkerService.deleteById(id);
        return Result.success("删除成功");
    }

    // ========== Evaluator ==========
    @GetMapping("/evaluator/page")
    public Result<PageResult<Evaluator>> getEvaluatorPage(EvaluatorPageQueryDTO evaluatorPageQueryDTO) {
        return Result.success(evaluatorService.pageQuery(evaluatorPageQueryDTO));
    }

    @PostMapping("/evaluator")
    public Result<String> addEvaluator(@RequestBody Evaluator evaluator) {
        evaluatorService.add(evaluator);
        return Result.success("添加成功");
    }

    @PutMapping("/evaluator")
    public Result<String> updateEvaluator(@RequestBody Evaluator evaluator) {
        evaluatorService.update(evaluator);
        return Result.success("更新成功");
    }

    @DeleteMapping("/evaluator/{id}")
    public Result<String> deleteEvaluator(@PathVariable Integer id) {
        evaluatorService.deleteById(id);
        return Result.success("删除成功");
    }
}
